package db

import "aicloud/monitor-apiserver/pkg/model"

func (d *DB) GetDataCenterCount() (int, error) {
	var count int64
	err := d.Model(&model.DataCenter{}).
		Distinct("data_center_name").
		Count(&count).Error
	if err != nil {
		return 0, err
	}
	return int(count), nil
}

func (d *DB) GetAllSupplierCount(idcName string) (int, error) {
	query := d.Model(&model.SupplierInfo{})
	if idcName != "" {
		query = query.Where("datacenter_name=?", idcName)
	}
	var count int64
	err := query.Count(&count).Error
	if err != nil {
		return 0, err
	}
	return int(count), nil
}

func (d *DB) GetAllSuppliers() ([]model.SupplierInfo, error) {
	var suppliers []model.SupplierInfo
	res := d.Model(&model.SupplierInfo{}).Find(&suppliers)
	if res.Error != nil {
		return nil, res.Error
	}
	return suppliers, nil
}
